package com.avengers.modules.spider.whois.querier;

import com.avengers.modules.spider.whois.bean.WhoisInfo;

import java.util.ArrayList;

/**
 * <p>
 * Domain Name: abc.cn
 * ROID: 20030311s10001s00033420-cn
 * Domain Status: clientTransferProhibited
 * Registrant ID: hc7122986545220
 * Registrant: 吴伟荣
 * Registrant Contact Email: abc.cn.jean@163.com
 * Sponsoring Registrar: 阿里云计算有限公司（万网）
 * Name Server: dns1.hichina.com
 * Name Server: dns2.hichina.com
 * Registration Time: 2003-03-17 12:20:05
 * Expiration Time: 2027-03-17 12:48:36
 * DNSSEC: unsigned
 * ************************************************************************************
 * % IANA WHOIS server
 * % for more information on IANA, visit http://www.iana.org
 * % This query returned 1 object
 * <p>
 * refer:        whois.cnnic.cn
 * <p>
 * domain:       CN
 * <p>
 * organisation: China Internet Network Information Center (CNNIC)
 * address:      No. 4, South 4th Street
 * address:      Zhong Guan Cun
 * address:      Beijing  100190
 * address:      China
 * <p>
 * contact:      administrative
 * name:         Yu Zeng
 * organisation: China Internet Network Information Center (CNNIC)
 * address:      No. 4, South 4th Street
 * address:      Zhong Guan Cun
 * address:      Beijing  100190
 * address:      China
 * phone:        +8610-58813686
 * fax-no:       +8610-58813632
 * e-mail:       ceo@cnnic.cn
 * <p>
 * contact:      technical
 * name:         Yuedong Zhang
 * organisation: China Internet Network Information Center (CNNIC)
 * address:      No. 4, South 4th Street
 * address:      Zhong Guan Cun
 * address:      Beijing  100190
 * address:      China
 * phone:        +8610-58813202
 * fax-no:       +8610-58812666
 * e-mail:       tech@cnnic.cn
 * <p>
 * nserver:      A.DNS.CN 2001:dc7:0:0:0:0:0:1 203.119.25.1
 * nserver:      B.DNS.CN 203.119.26.1
 * nserver:      C.DNS.CN 203.119.27.1
 * nserver:      D.DNS.CN 2001:dc7:1000:0:0:0:0:1 203.119.28.1
 * nserver:      E.DNS.CN 203.119.29.1
 * nserver:      F.DNS.CN 195.219.8.90
 * nserver:      G.DNS.CN 66.198.183.65
 * nserver:      NS.CERNET.NET 202.112.0.44
 * ds-rdata:     57724 8 2 5D0423633EB24A499BE78AA22D1C0C9BA36218FF49FD95A4CDF1A4AD97C67044
 * <p>
 * whois:        whois.cnnic.cn
 * <p>
 * status:       ACTIVE
 * remarks:      Registration information: http://www.cnnic.cn/
 * <p>
 * created:      1990-11-28
 * changed:      2018-03-01
 * source:       IANA
 * <p>
 * the Domain Name you apply can not be registered online. Please consult your Domain Name registrar
 *
 * @author yu.wang
 * @since 2019/1/2 上午11:51
 **/
class Cn implements WhoisAnalysis {
    public static final Cn ANALYSIS = new Cn();
    private static final String UN_REGISTERED_ONLINE_REMARK = "the Domain Name you apply can not be registered online. Please consult your Domain Name registrar";
    private Cn() {
    }

    @Override
    public String server() {
        return "whois.cnnic.cn";
    }

    @Override
    public String notFoundRemark() {
        return "No matching record";
    }

    @Override
    public String unRegisteredOnLineRemark() {
        return UN_REGISTERED_ONLINE_REMARK;
    }

    @Override
    public void transferLine(WhoisInfo info, String line) {
        if (line.contains("ROID:")) {
            info.setRegistryDomainId(line.replace("ROID:", "").trim());
        } else if (line.contains("Registrant ID:")) {
            info.setContactId(line.replace("Registrant ID:", "").trim());
        } else if (line.contains("Registrant:")) {
            info.setContactName(line.replace("Registrant:", "").trim());
        } else if (line.contains("Registrant Contact Email:")) {
            info.setContactEmail(line.replace("Registrant Contact Email:", "").trim());
        } else if (line.contains("Sponsoring Registrar:")) {
            info.setRegistrar(line.replace("Sponsoring Registrar:", "").trim());
        } else if (line.contains("Registration Time:")) {
            info.setCreateDate(line.replace("Registration Time:", "").trim());
        } else if (line.contains("Expiration Time:")) {
            info.setExpiryDate(line.replace("Expiration Time:", "").trim());
        } else if (line.contains("Registrar Abuse Contact Phone:")) {
            info.setContactPhone(line.replace("Registrar Abuse Contact Phone:", "").trim());
        } else if (line.contains("Domain Status:")) {
            if (null == info.getStatusList()) {
                info.setStatusList(new ArrayList<>());
            }
            info.getStatusList().add(line.replace("Domain Status:", "").trim());
        } else if (line.contains("Name Server:")) {
            if (null == info.getNameServerList()) {
                info.setNameServerList(new ArrayList<>());
            }
            info.getNameServerList().add(line.replace("Name Server:", "").trim());
        } else if (line.contains("DNSSEC:")) {
            info.setDnsSec(line.replace("DNSSEC:", "").trim());
        } else if (line.contains(UN_REGISTERED_ONLINE_REMARK)) {
            // 被保留
            info.setRetained(true);
        }
    }
}
